﻿using System;
using System.Globalization;

namespace Otgruzka.Controls.jQuery
{
    public static class StringExtensions
    {
        public static DateTime? GetDateFromString(this string dateString)
        {
            if (!string.IsNullOrEmpty(dateString.Trim()))
            {
                DateTime res;
                if (DateTime.TryParseExact(
                    dateString,
                    "dd.MM.yyyy",
                    CultureInfo.CurrentCulture,
                    DateTimeStyles.None,
                    out res))
                {
                    return res;
                }
            }
            return null;
        }

        public static string GetEscapedString(this string input)
        {
            string res = "";
            res = input.Replace("'", "&#8242;").Replace("\"", "&#34;");
            return res;
        }

        public static double GetDoubleFromString(this string input)
        {
            string res = "";
            res = input.Replace(" ","").Replace(".", ",");
            return Convert.ToDouble(res);
        }
    }
}